package fr.uniscol.siecle.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Academie implements Serializable, DonneeSiecle {

	private String code = null;
	
	private String nom = null;

	private List<Departement> departements = null;
	
	public Academie() {
	}

	public Academie(String code, String nom) {
		super();
		this.code = code;
		this.nom = nom;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getNom() {
		if(nom == null){
			nom = "";
		}
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public List<Departement> getDepartements() {
		if(departements == null){
			departements = new ArrayList<Departement>();
		}
		return departements;
	}

	public void setDepartements(List<Departement> departements) {
		this.departements = departements;
	}
	
	public Departement getDepartement(String code){
		for(Departement d : getDepartements()){
			if(d.getCode().equals(code)){
				return d;
			}
		}
		return null;
	}
	
	public void ajouterDepartement(Departement d){
		if(!getDepartements().contains(d)){
			getDepartements().add(d);
		}
		if(d.getAcademie() == null || !d.getAcademie().equals(this)){
			d.setAcademie(this);
		}
	}

	@Override
	public boolean equals(Object a) {
		return getCode() == ((Academie)a).getCode();
	}
}
